home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM B4 / PD-ROM B4.iso / Entertainment / Strategy / Robots / bot 1.0.1 / Tutorial / BASIC / Bomber next >
Text File  |  1991-06-25  |  2KB  |  80 lines

  1. !
  2. ! Bomber
  3. !
  4. ! This bot recognizes when it takes damage, and it tries to run
  5. ! away when it gets hit.
  6. ! Its weapon is a grenade launcher, not an ordinary gun.
  7. !
  8.  
  9. #DATA
  10.  
  11. EQU INCR    23
  12. EQU MINDIST 25
  13.  
  14. DEF damage
  15. DEF scanAt
  16. DEF XX                  ! Destination coordinates
  17. DEF YY
  18. DEF goX                 ! Prepared velocities for running away
  19. DEF goY
  20.  
  21. #CODE BASIC
  22.  
  23. :Initialize
  24.     Gosub CalcPos       ! Pick a point to go to
  25.     goX = goX * 20      ! Prepare to accelerate an awful lot
  26.     goY = goY * 20
  27.     damage = $DAMAGE    ! Remember current damage level
  28.  
  29.     While (damage == $DAMAGE)    ! Until I get hit
  30.       begin
  31.         ScanAt = ScanAt + INCR
  32.         Scan Angle ScanAt
  33.         
  34.         ! Don't launch so close that you hit yourself!  If the
  35.         ! enemy is close, aim MINDIST pixels away.  But, the
  36.         ! first check is to see if something was found.
  37.         
  38.         If ($FOUND <> 0) Then If ($DISTANCE >= MINDIST) &
  39.           Then Fire Weapon 1, Angle $ANGLE, Distance $DISTANCE
  40.           Else Fire Weapon 1, Angle $ANGLE, Distance MINDIST
  41.  
  42.         ! Don't bother "locking" on to the enemy, because
  43.         ! grenades are pretty slow to fire and detonate.
  44.       end
  45.     
  46.     Goto Runaway
  47.  
  48. :RAway
  49.     Gosub CalcVel
  50.     goX = goX * 2       ! Move there twice as fast.
  51.     goY = goY * 2
  52. :Runaway
  53.     Velocity goX, goY
  54.     If (XX-$XLOC > 30) Then Goto RAway
  55.     If (XX-$XLOC < -30) Then Goto RAway
  56.     If (YY-$YLOC > 30) Then Goto RAway
  57.     If (YY-$YLOC < -30) Then Goto RAway
  58.     
  59.     ! If we got this far, we must be within 30 pixels (both X
  60.     ! and Y) of our destination.  Close enough.
  61.     
  62.     Velocity 0, 0
  63.     Goto Initialize     ! Start all over again.
  64.  
  65.  
  66. ! These are subroutines.  CALCVEL calculates the new velocity
  67. ! for moving to point XX,YY.  CALCPOS does the same, except
  68. ! that it also picks random numbers between 20 and 235 for
  69. ! XX and YY.
  70.  
  71. :CalcPos
  72.     XX = Random(215) + 20
  73.     YY = Random(215) + 20
  74. :CalcVel
  75.     goX = XX - $XLOC
  76.     goY = YY - $YLOC
  77.   Return
  78.  
  79. #END
  80.